<template>
  <view class="flex-col">
    <view :class="boole?'bottom115':''">
      <!--申请信息 -->
      <newApplication v-model="ruleForm" title="申请信息" :boole="boole" ref="refNewApplication"/>

      <!--审批流程-->
      <exam-flow v-if="flowId" :instanceId="flowId"/>
    </view>

    <view class="button-container" v-if="boole">
      <button class="btn-item" @click="submit">提 交</button>
    </view>


  </view>
</template>

<script>
import * as apis from '@/api/routineApplyFor'
import newApplication from './components/newApplication.vue'

export default {
  name: 'add',
  components: {newApplication},
  computed: {},
  watch: {},
  onLoad(op) {
    let title = "";
    this.flowId = op?.flowId
    if (op?.type === "edit") {
      title = "新增处置申请";
      this.boole = true;
    }
    if (op?.type === "view") {
      title = "查看处置申请";
      this.boole = false;
    }
    if (op?.id) {
      this.handleDetail(op?.id)
    }
    uni.setNavigationBarTitle({
      title,
    });
  },
  data() {
    return {
      ruleForm: {
        carId: null,
        carNo: '',
        vinNo: '',
        brandId: '',
        seriesId: '',
        modelId: '',
        brandName: '',
        modelName: '',
        seriesName: '',
        propertyRightId: '',
        propertyRightName: '',
        registerTime: '',
        carAge: '',
        environmentalStandards: '',
        licenseNature: '',
        fuelType: '',
        liter: '',
        seatNum: '',
        gearPosition: '',
        exteriorColor: '',
        carType: '',
        accidentAmountThreeYears: '',
        guidancePrice: '',
        purchasePrice: '',
        initialResidualValue: '',
        mileage: '',
        transferCount: '',
        vehicleConditionLevel: '',
        cityName: '',
        disposalReason: '',
        vehicleStatus: '',
        attachment: ''
      },
      boole: false,
      flowId: null,
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    async handleDetail(id) {
      this.loading = true
      try {
        const res = await apis.vehicleDisposalDetails(id)
        this.ruleForm = {...res.data}
        this.ruleForm.vehicleDisposalId = id
      } catch (e) {
        console.error(e)
      } finally {
        this.loading = false
      }
    },

    async submit() {
      try {
        await this.$refs.refNewApplication.handleEffect();
        uni.showLoading();
        const res = await apis?.vehicleDisposal(this.ruleForm);
        if (res.code === 200) {
          uni.$emit("refBackList", true);
          this.$modal.msgSuccess("提交成功");
          setTimeout(() => {
            this.$tab.navigateBack();
          }, 1000);
        }
      } catch (error) {
        this.$nextTick(() => {
          uni.pageScrollTo({
            selector: error,
          });
        });
      } finally {
        setTimeout(() => {
          uni.hideLoading()
        }, 1000)
      }
    }
  },
};
</script>

<style scoped lang=""></style>


